﻿@{
    var leave = ViewBag.Leave as AdverseEventReportSystem.BLL.SchedulingSystem.Leave;
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js"></script>
    <script src="~/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
</head>
<body>
    <div style="margin:10px 0px;">
        <table class="gridtable">
            <tr>
                <td style="text-align:right; width:80px;">
                    休假人员：
                </td>
                <td>
                    <div style="float:left;margin-top:4px;"><input type="text" id="useId" value="@(leave.Id==0?"-1":leave.UserId)" /></div><font style="color:red;">&nbsp;*</font>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px;">
                    休假日期：
                </td>
                <td>
                    <div style="float:left;margin-top:4px;"><input type="text" id="txtStartDate" value="@(leave.Id == 0 ? "" : DateTime.Parse(leave.StartTime.ToString()).ToString("yyyy-MM-dd hh:mm"))" /></div>
                    <div style="float:left;margin:0px 5px;"> - </div>
                    <div style="float:left;margin-top:4px;"><input type="text" id="txtEndDate" value="@(leave.Id == 0 ? "" : DateTime.Parse(leave.EndTime.ToString()).ToString("yyyy-MM-dd hh:mm"))" /></div>
                    <font style="color:red;">&nbsp;*</font>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px;">
                    休假天数：
                </td>
                <td>
                    <input type="text" id="txtDays" class="l-text" style="width:200px;" value="@(leave.Days)" /><font style="color:red;">&nbsp;*</font>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px;">
                    休假类别：
                </td>
                <td>
                    <div style="float:left;margin-top:4px;"><input type="text" id="holidayTypeId" value="@(leave.Id==0?-1:leave.TypeId)" /></div><font style="color:red;">&nbsp;*</font>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;padding-top:10px;">
                    <input id="btnSubmit" type="button" value="确定" class="l-button" onclick="save()" />&nbsp;&nbsp;&nbsp;
                    <input id="btnCancel" type="button" value="取消" class="l-button-cancel" onclick="closeDialog()" />
                </td>
            </tr>
            <tr></tr>
        </table>
        <input type="hidden" id="hdnLeaveId" value="@(leave.Id)" />
    </div>
</body>
</html>
<script>
    $(function () {
        $("#txtStartDate,#txtEndDate").ligerDateEditor({
            showTime: true,
            format: "yyyy-MM-dd hh:mm",
            width: 140,
            cancelable: false
        });

        $("#useId").ligerComboBox({
            cancelable: false,
            width: 140,
            url: "/AdverseEvent/EditAdverseEvent/GetNurseList?ram" + Math.random(),
            parms: { isAll: 1 },
            valueField: "UserId",
            textField: "UserName",
            valueFieldID: 'hdnUserId',
            value: $("#useId").val()
        });

        $("#holidayTypeId").ligerComboBox({
            cancelable: false,
            width: 140,
            url: "/Scheduling/Leave/GetHolidayTypeList?ram" + Math.random(),
            parms: { isAll: 1 },
            valueField: "Id",
            textField: "HolidayTypeName",
            valueFieldID: 'hdnHolidayTypeId',
            value: $("#holidayTypeId").val()
        });
    });

    function save() {
        var Id = $("#hdnLeaveId").val();
        var userId = $("#hdnUserId").val();
        var userName = $("#useId").ligerComboBox().getText();
        var startDate = $("#txtStartDate").val();
        var endDate = $("#txtEndDate").val();
        var days = $("#txtDays").val();
        var holidayTypeId = $("#hdnHolidayTypeId").val();
        var holidayTypeName = $("#holidayTypeId").ligerComboBox().getText();

        if (userId == "-1") {
            $.ligerDialog.error("请选择休假人员");
            $("#useId").focus();
            return;
        }
        if (IsEmpty(startDate)) {
            $.ligerDialog.error("休假开始日期不能为空");
            $("#txtStartDate").focus();
            return;
        }
        if (IsEmpty(endDate)) {
            $.ligerDialog.error("休假结束日期不能为空");
            $("#txtEndDate").focus();
            return;
        }
        if (IsEmpty(days)) {
            $.ligerDialog.error("休假天数不能为空");
            $("#txtDays").focus();
            return;
        }
        if (holidayTypeId == "-1") {
            $.ligerDialog.error("请选择休假类别");
            $("#holidayTypeId").focus();
            return;
        }

        var dialog = frameElement.dialog;
        $.ajax({
            url: "/Scheduling/Leave/Save",
            type: "post",
            data: {
                Id: $("#hdnLeaveId").val(),
                UserId: userId,
                UserName: userName,
                StartTime: startDate,
                EndTime: endDate,
                Days: days,
                TypeId: holidayTypeId,
                TypeName: holidayTypeName
            },
            success: function (r) {
                var r = $.parseJSON(r);
                if (r.Result == 1) {
                    parent.$("#btnSearch").click();
                    dialog.close();
                }
                else if (r.Result == 0) {
                    $.ligerDialog.error(r.Body);
                }
                else {
                    $.ligerDialog.error("程序错误");
                }
            },
            error: function () {
                $.ligerDialog.error("程序错误");
            }
        });
    }

    function closeDialog() {
        frameElement.dialog.close();//关闭dialog
    }
</script>